# -*- coding: utf-8 -*-
# @Time    : 2024/1/11 21:18
# @Author  : micah
# @File    : 17.使用bs4提取搜狗微信文章.py
# @Software: PyCharm


import requests
from bs4 import BeautifulSoup


url = 'https://weixin.sogou.com/weixin?_sug_type_=1&type=2&query=python'

headers = {
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
}

response = requests.get(url, headers=headers).text
soup = BeautifulSoup(response, 'lxml')
# ul_tag = soup.select('ul[class="news-list"]')
ul_tag = soup.find_all('ul', class_='news-list')

h3_list = ul_tag[0].select('h3')
for temp in h3_list:
    print(temp.select('a')[0].text, temp.select('a')[0].get('href'))




